//
//  WCBAdressViewModel.m
//  WeChatBuniess
//
//  Created by TFAppleWork-Summer on 2017/12/15.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "WCBAdressViewModel.h"
#import "WCBDataHelper.h"
#import "WCBRegionModel.h"
#import "UIScreen+Extend.h"

@implementation WCBAdressViewModel

- (void)setModel:(WCBAdressModel *)model{
    _model = model;
    NSArray *allAdress = [[WCBDataHelper sharedHelper]getAllRegionArray];
    NSString *prvString;
    NSString *cityString;
    NSString *areaString;
    for (NSDictionary *dic in allAdress)
    {
        WCBRegionModel *regionModel = [WCBRegionModel modelWithDict:dic];
        if (regionModel.locationId == [model.prov integerValue])
        {
            prvString = regionModel.locationName;
        }
        else if (regionModel.locationId == [model.city integerValue])
        {
            cityString = regionModel.locationName;
        }
        else if (regionModel.locationId == [model.area integerValue])
        {
            areaString = regionModel.locationName;
        }
    }
    self.adressString = [NSString stringWithFormat:@"%@%@%@",prvString?prvString:@"",cityString?cityString:@"",areaString?areaString:@""];
    
    
    NSString *fullAdressString = nil;
    if ([self.model.isdefault  isEqualToString:@"1"]) {
        fullAdressString = [NSString stringWithFormat:@"[默认地址]%@",self.model.addressDesc];
    }
    else
    {
        fullAdressString = self.model.addressDesc;
    }
    
     CGSize size =[fullAdressString boundingRectWithSize:CGSizeMake([UIScreen width] - 90, MAXFLOAT)
                                                 options:NSStringDrawingUsesLineFragmentOrigin
                                              attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:25]} context:nil].size;
    self.adressHeight = size.height;
}
@end
